package com.ita.dispatcher;

import com.ita.icommand.Command;
import com.ita.util.PrintHelper;

/***
 * command sender
 * @author Elvis
 *
 */
public class CommandDispatcher {

	private Command aCommand, dCommand, uCommand, oCommand, lCommand;

	public CommandDispatcher(Command aCommand, Command dCommand, Command uCommand, Command oCommand, Command lCommand) {
		super();
		this.aCommand = aCommand;
		this.dCommand = dCommand;
		this.uCommand = uCommand;
		this.oCommand = oCommand;
		this.lCommand = lCommand;
	}

	public void action(String s) {
		String input=s;
		try {

			switch (s.toUpperCase().substring(0, 1)) {

			case "L":
				lCommand.execute(input);
				break;
			case "H":
				if (input.toUpperCase().startsWith("H A")) {
					PrintHelper.printAddHelp();
				} else {
					PrintHelper.printHelpDoc();
				}
				break;
			case "A":
				aCommand.execute(input);
				break;
			case "O":
				oCommand.execute(input);
				break;
			case "D":
				dCommand.execute(input);
				break;
			case "U":
				uCommand.execute(input);
				break;
			default:
				System.out.println("plz enter right command!");

			}
		} catch (Exception e) {
			System.out.println("plz check your command");
		}
	}

}
